﻿using System;
using System.Windows.Forms;

namespace WindowsAPI.DWM
{
    public partial class Thumbnail : Form
    {
        private IntPtr lv_hThumbnailHandle;

        public Thumbnail() { InitializeComponent(); }

        public void CreateAndShow(IntPtr sourceWindow)
        {
            lv_hThumbnailHandle = DwmApi.DwmRegisterThumbnail(
                Handle, sourceWindow);

            var lv_ThumbnailProperties = new ThumbnailProperties
                                             {
                                                 Flags = ThumbnailPropertiesFlags.Visible |
                                                           ThumbnailPropertiesFlags.Opacity |
                                                           ThumbnailPropertiesFlags.RectDestination |
                                                           ThumbnailPropertiesFlags.SourceClienAtreaOnly,
                                                 Opacity = 255,
                                                 Visible = true,
                                                 SourceClientAreaOnly = false
                                             };

            lv_ThumbnailProperties.Source =
                lv_ThumbnailProperties.Destination = new RECT(0, 0, ClientRectangle.Right, ClientRectangle.Bottom);

            DwmApi.DwmUpdateThumbnailProperties(lv_hThumbnailHandle, lv_ThumbnailProperties);

            Show();
        }
    }
}
